﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZK.MyControl
{
     public  class MyMonthCalendar:Label
    {

        public MyMonthCalendar()
        {
            this.AutoSize = false;
            this.Size = new System.Drawing.Size(350, 50);
            this.Font = new System.Drawing.Font("宋体", 30, System.Drawing.FontStyle.Bold);
            this.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            this.BorderStyle = BorderStyle.FixedSingle;
            this.Click += MyMonthCalendar_Click;
            this.Text = dateTime.ToString("yyyy-MM-dd");
            this.Name = this.Text;
            this.Invalidate();
            
        }

        private DateTime dateTime = DateTime.Now;
        public DateTime DateTime
        {
            get
            {
                return dateTime;
            }
            set
            {
                dateTime = value;
                this.Text = dateTime.ToString("yyyy-MM-dd");
                this.Invalidate();
                if (ValueChanged != null)
                {
                    ValueChanged(dateTime, null);
                }
            }
        }

        private void MyMonthCalendar_Click(object sender, EventArgs e)
        {
            FrmMonthCalendar frmMonthCalendar = new FrmMonthCalendar();
            frmMonthCalendar.Datetime = this.DateTime;
            frmMonthCalendar.ShowDialog();
            this.DateTime = frmMonthCalendar.Datetime;
        }

        public EventHandler ValueChanged;
    }
}
